package com.serv.common.service.sys;

import com.serv.common.base.BaseService;
import com.serv.common.model.sys.Organization;

public class OrganizationService extends BaseService<Organization> {
	private String rootId = "000";
	
	public OrganizationService() {
		this.dao = Organization.dao;
	}
	
	public Organization getRoot() {
		Organization root = dao.findById(rootId);
		if(root == null) {
			root = new Organization()
				.set("id",rootId)
				.set("name","根组织")
				.set("remark","根组织，不能删除");
			if(root.save()) System.out.println("插入一条根组织数据");insertDemo(5);
		}
		return root;
	}

	private void insertDemo(int count) {
		String id0 = "000";
		for(int i=0;i<count;i++) {
			String id1 = id0+String.format("%03d",i);
			new Organization().set("id",id1).set("name","组织"+id1)
			.set("remark","这是组织"+id1+"的备注信息").save();
			
			for(int j=0;j<count;j++) {
				String id2 = id1+String.format("%03d",j);
				new Organization().set("id",id2).set("name","组织"+id2)
				.set("remark","这是组织"+id2+"的备注信息").save();
				
				for(int k=0;k<count;k++) {
					String id3 = id2+String.format("%03d",k);
					new Organization().set("id",id3).set("name","组织"+id3)
					.set("remark","这是组织"+id3+"的备注信息").save();
					
					for(int m=0;m<count;m++) {
						String id4 = id3+String.format("%03d",m);
						new Organization().set("id",id4).set("name","组织"+id4)
						.set("remark","这是组织"+id4+"的备注信息").save();
					}
				}
			}
		}
	}
}
